<!doctype html>
<html class="no-js">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>党建网</title> 
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="../../assets/css/amazeui.css"/>
  <link rel="stylesheet" href="../../assets/css/admin.css">
  <link rel="stylesheet" href="../../css/amazeui.datetimepicker.css" />

</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->

<header class="am-topbar amt-header">
</header>

<div class="am-cf">
  <!-- sidebar start -->
   <div class="admin-sidebar am-offcanvas" id="admin-offcanvas">
  </div>
  <!-- sidebar end -->

  <!-- content start -->
  <div class="admin-content">
      <div class="admin-content-body">
		<div class="am-cf am-padding" style="margin-left:2%">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg" style="color:#BD2D30">信息详情</strong></div>
        </div>

				<form class="am-form am-form-horizontal">
					<div class="am-form-group">
						<label for="" class="am-u-sm-1 am-form-label">主栏目</label>
                            <div class="am-u-sm-2 am-u-end col-end" style="padding-top:10px">
                                <select data-am-selected id="mcol">
                                    
                                </select> 
                            </div>
					</div>
                    
                    	<div class="am-form-group">
						<label for="" class="am-u-sm-1 am-form-label">子栏目</label>
                            <div class="am-u-sm-2 am-u-end col-end" style="padding-top:10px" id="ssscol">
                                <select data-am-selected id="scol">
                                </select>
                            </div>
					</div>

					<div class="am-form-group">
						<label for="author_ipt" class="am-u-sm-1 am-form-label">标题</label>
						<div class="am-u-sm-10 am-u-end col-end" style="padding-top:10px">
							<input type="text" id="name" placeholder="请输入标题">
						</div>
					</div>

					<div class="am-form-group">
						<label for="editor" class="am-u-sm-1 am-form-label">正文</label>
						<div class="am-u-sm-10 am-u-end col-end" style="padding-top:10px">
							<script id="editor" type="text/plain" style="width:100%;height:500px;"></script>
						</div>
					</div>
				</form>

				<div class="am-g" style="margin-top:10px">
					<div class="am-u-sm-10 am-u-sm-centered" style="text-align:right">
						<button type="button" class="am-btn am-btn-primary" id="pub_btn" style="background:#BD2D30;border-color:#BD2D30">更新</button>
                        <button type="button" class="am-btn am-btn-primary" id="" style="background:#BD2D30;border-color:#BD2D30;margin-left:1%">取消</button>
					</div>
				</div>

			</div>


  </div>
  <!-- content end -->

</div>

<a href="#" class="am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}">
  <span class="am-icon-btn am-icon-th-list"></span>
</a>


<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="/assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="../../assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="../../assets/js/amazeui.min.js"></script>
<script src="../../js/left-nav.js"></script>
<script src="../../js/header.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../../ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/amazeui.datetimepicker.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../../js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="../../js/index.js"></script>
<script src="../../js/global.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
        $("#collapse-nav-2").addClass("am-in");
        searchMcol();
		
        var pkArticle = getCookie("pkArticle");
        $.ajax({
    		type : "GET",
    		url : "/partyBuilding/article/"+pkArticle ,
    		contentType : "application/json",
    		dataType : "json",
    		success : function(data) {
    			//alert(JSON.stringify(data));
    			
    			if(data.code == "200") {
    				
    				var fkMcol = data.article.fkMcol;
    				var fkScol = data.article.fkScol;
    				
    				$("#mcol").find("option[value='"+fkMcol+"']").attr("selected","selected");
    				
    				showScol(fkScol);
    				
    				$("#name").val(data.article.artTitle);
    				
    				var ue = UE.getEditor('editor');
    				ue.addListener("ready", function () {
    	        	// editor准备好之后才可以使用
    	        	ue.setContent(data.article.articleContent);

    	        	});
    			}
    		},
    		error : function() {
    			
    		}
    	}); 
        
    })
    

		//实例化编辑器
		//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
		
/*   更新信息 */

$("#pub_btn").click(
			function() {
				var content = {};
				var pkArticle = getCookie("pkArticle");
				content["pkArticle"] = pkArticle;
				//主栏目
				var mcol = $("#mcol").val();
				if(mcol==000){
					alertModal("提示", "请选择主栏目");
					return false;
				}
				content["fkMcol"] = mcol;
				//子栏目
				var scol = $("#scol").val();
				if(scol==000){
					alertModal("提示", "请选择子栏目");
					return false;
				}
				content["fkScol"] = scol;
				
				// 标题
				var artTitle = $("#name").val();
				
				if (artTitle == "") {
					alertModal("提示", "标题未填写");
					return false;
				}
				content["artTitle"] = artTitle;


				// 正文
				var ue = UE.getEditor('editor');
				var articleContent = ue.getContent();
				if (articleContent == "") { // 若公告链接未填写，需检查正文内容是否为空
					alertModal("提示", "正文内容为空");
					return false;
				}else{
				content["articleContent"] = articleContent;
				alert(JSON.stringify(content));
				saveNews(content);
				}
				
				

			});

	/* 保存公告 */
	function saveNews(content) {
		$.ajax({
			type : "POST",
			url : "/partyBuilding/article/update",
			data : encrypt(content),
			contentType : "application/json",
			dataType : "json",
			success : function(data) {
				ALERT(JSON.stringify(data));
				if (data.code == "200") {
					alertModal("提示", "修改成功", function() {
					});
				} else {
					alertModal("警告", data.msg);
				}
			},
			error : function() {
				alertModal("警告", "服务器开小差了");
			}
		});
	}



	</script>
</body>
</html>
